package com.bestvike.stone.spring.redis.converter;

import com.bestvike.linq.exception.NotSupportedException;
import com.bestvike.stone.core.collection.ArrayUtils;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

import java.nio.charset.StandardCharsets;

/**
 * Created by 许崇雷 on 2018/5/30.
 */
public final class ObjectRedisSerializer implements RedisSerializer<Object> {
    public static final ObjectRedisSerializer DEFAULT = new ObjectRedisSerializer();

    private ObjectRedisSerializer() {
    }

    @Override
    public byte[] serialize(Object value) throws SerializationException {
        return value == null ? ArrayUtils.EMPTY_BYTE_ARRAY : value.toString().getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public Object deserialize(byte[] bytes) throws SerializationException {
        throw new NotSupportedException("deserialize not supported.");
    }
}
